package com.example.dilidili_ting.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.dilidili_ting.R;
import com.example.dilidili_ting.activity.MovielistActivityTing;
import com.example.dilidili_ting.bean.MovieTypeTing;

import java.util.List;

public class HomeAdapterTing extends BaseAdapter {
    private Context contextTing;
    private List<MovieTypeTing> dataTing;

    //    构造函数
    public HomeAdapterTing(Context context,  List<MovieTypeTing> data) {
        this.contextTing=context;
        this.dataTing=data;
    }

    static class ViewHolder{
        public TextView typeTing, countTing;
        public ImageView iconTing;
        public RelativeLayout typeCardTing;
    }

    @Override
    public int getCount() {
        return dataTing.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    //    设置页面
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder vh;
        if (convertView==null){
            vh=new ViewHolder();
            convertView= LayoutInflater.from(contextTing).inflate(R.layout.movietype_item_ting,parent,false);
            vh.typeTing=convertView.findViewById(R.id.type_ting);
            vh.countTing=convertView.findViewById(R.id.count_ting);
            vh.iconTing=convertView.findViewById(R.id.icon_ting);
            vh.typeCardTing=convertView.findViewById(R.id.type_card_ting);
            convertView.setTag(vh);
        } else {
            vh= (ViewHolder) convertView.getTag();
        }
        vh.typeTing.setText(dataTing.get(position).getType());
        vh.countTing.setText(dataTing.get(position).getCount());
        vh.iconTing.setImageResource(dataTing.get(position).getIconSrc());
        vh.typeCardTing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO: 2021/6/17 调接口传入信息,获取不同类别的电影目录,并跳转页面
                Intent intent = new Intent(contextTing, MovielistActivityTing.class);
                intent.putExtra("type", dataTing.get(position).getType());
                contextTing.startActivity(intent);
            }
        });
        return convertView;
    }
}

